﻿<style type='text/css'>
    .summerTable {
        border-collapse: collapse;
        margin: 0 auto;
        width: 100%;
    }

        .summerTable td {
            border: 1px solid #ddd;
            color: #333;
            padding: 5px;
            text-align: left;
        }

        .summerTable th {
            background-color: #eee;
            border: 1px solid #ddd;
            padding: 5px;
            text-align: left;
            color: #111;
        }
</style>

<div id="dms_Summary" style="margin-bottom:10px;">

</div>

<div style="border-bottom:1px solid #eee; padding:10px;text-align:right;margin-bottom:10px;">
    <button id="closeIframe" class="btn btn-default">Close</button>
    <button id="AddFile" class="btn btn-danger">Add File</button>
</div>

<div id="dms" style="display:none;">
    <iframe id="myIframe" src="" style="width:100%;height:1000px;border:0px;"></iframe>
</div>
<script>
    var Addurl = "https://appcn.digitalmaker.pwccn.com/dlcmstestdrive/dlcmsvopo/vForm/Document/Add?DocumentType=DEFAULT&appcode=gtsventure&_id={0}";
    var Viewurl = "https://appcn.digitalmaker.pwccn.com/dlcmstestdrive/dlcmsvopo/vForm/Document/Preview/{0}/";
    var apiurl = "/dlcmstestdrive/dlcmsvopo/CustomApi/RetrieveQueryDocs";

function dms_Summary(BusinessId){
console.log("BusinessId",BusinessId);
 $("#dms").hide();
 $("#myIframe").attr("src",'');
	 var searchItem = [];
            searchItem.push({
                Method: "And",
                Operator: "Equal",
                Name: "BusinessID",
                Value: BusinessId
            });

	var Jsondata = {};
	Jsondata.Token = "";
	Jsondata.EntityName = "o7hxn3ou8sn";
	Jsondata.size = 1000000;
	Jsondata.index = 0;
	Jsondata.SearchItem = searchItem;
	Jsondata.Order = { "C4-ModifyDate": "Descending" };

	var resultTable="<table class='summerTable'><tr><th>Number</th><th>FileName</th><th>Format</th><th>Create Date</th><th>View</th></tr>";
	$.post(apiurl, Jsondata, function (response) {
       console.log("dms_Summary", response);
	   var exist=false;
	   for(i=0;i<response.Data.rows.length;i++){
	     exist=true;
	     var o=response.Data.rows[i];
		 var tr="<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>";
		 tr=tr.replace("{0}",(i+1).toString());
		 tr=tr.replace("{1}",o.Title);
		 tr=tr.replace("{2}",o.Format);
		 tr=tr.replace("{3}",moment(o["C4-CreateDate"]).format("DD MMM YYYY"));
		 var link="<a href='##' onclick=\"dms_open('"+o._id+"','edit')\" >view</a>";
		 tr=tr.replace("{4}",link);
		 resultTable=resultTable+tr;
	   }
	   if(!exist){resultTable=resultTable+"<tr><td colspan='8' style='text-align:center;'>No record.</td></tr>";}
	   resultTable+="</table>";
	   $("#dms_Summary").html(resultTable);
	    $("#closeIframe").hide();
    });
}

function dms_open(id,type){
    $("#closeIframe").show();
	var turl=type=='add'?Addurl:Viewurl;
	turl=turl.replace("{0}",id);
	$("#myIframe").attr("src",turl);
	$("#myIframe").attr("style", "width:100%;height:1000px;border:0px;");
	$("#myIframe").load(function () {
	    $("#myIframe").contents().find(".SysBtnClose").hide();
	});
	$("#dms").show();
}

$(function(){
 console.log(moment());
  var formid=$("input[name='_id']").val();
  dms_Summary(formid);
  $("#AddFile").click(function(){
  dms_open(formid,'add');
  });

  $("#closeIframe").hide();
  $("#closeIframe").click(function(){
      $("#myIframe").attr("src", '');
      $("#closeIframe").hide();
      $("#myIframe").attr("style","width:100%;height:0px;border:0px;");
      $("#dms").show();
  });

});



</script>






//获取url参数
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return ''; //返回参数值
};

function proccessIframe(){
 if(self==top)return;
 var pagemode = AppDesign.Document.pageMode;
  var BusinessId=$("#Metadata-BusinessID").val();
 if(pagemode=='add'){
	 BusinessId=getUrlParam("_id");
	 var AppCode=getUrlParam("appcode");
	 $("#Metadata-BusinessID").val(BusinessId);
	 $("#Metadata-AppCode").val(AppCode);
 }
 if(BusinessId=='') $("#navbar,#footer").hide();
};

$(function(){
 proccessIframe();
});




Button 按钮加脚本
var BusinessId=$("#Metadata-BusinessID").val();
if(BusinessId!=''&&self!=top)parent.dms_Summary(BusinessId);
